function data = get_datalast(ptstruct,ids,dt)
% Get data from the patients

if ~iscell(ids)
    h{1} = ids;
    ids = h;
end

data{length(ids)} = [];

for n = 1 : length(ids)
     data{n} = [];
     for pt = ids{n}
         t = max([max(ptstruct(pt).data{1}.hr(:,1)),max(ptstruct(pt).data{1}.uo(:,1)),...
             max(ptstruct(pt).data{1}.pulsep(:,1)),max(ptstruct(pt).data{1}.lactate(:,1))]);
         
         indhr = find(ptstruct(pt).data{1}.hr(:,1) >= t-dt);
         indpp = find(ptstruct(pt).data{1}.pulsep(:,1) >= t-dt);
         indla = find(ptstruct(pt).data{1}.lactate(:,1) >= t-dt);
         induo = find(ptstruct(pt).data{1}.uo(:,1) >= t-dt);
         data{n} = [data{n}; ...
             median(ptstruct(pt).data{1}.hr(indhr,2)), ...
             median(ptstruct(pt).data{1}.pulsep(indpp,2)), ...
             median(ptstruct(pt).data{1}.lactate(indla,2)), ...
             median(ptstruct(pt).data{1}.uo(induo,2))];
     end
end

% Perfect